package hpp.collection;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by hpp on 2017/8/26.
 */
public class ArrayListTest {

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add(0, "5");
//        for (String item:list) {
//            System.out.println(item);
//        }

        System.out.println("the first element is: "+ list.get(0));
        list.remove("3");
                for (String item:list) {
            System.out.println(item);
        }
        System.out.println("Arraylist size=: "+ list.size());
        System.out.println("ArrayList contains 3 is: "+ list.contains("3"));
        list.set(1, "10");
        for(Iterator iter = list.iterator(); iter.hasNext(); )
        {
            System.out.println("next is: "+ iter.next());
        }
        String[] arr = list.toArray(new String[0]);
        for (String str:arr)
            System.out.println("str: "+ str);
        list.clear();
        System.out.println("ArrayList is empty: " + list.isEmpty());
    }
}
